package com.qidianit.mes.pro.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.pro.ProductionReport;
import com.qidianit.mes.pro.service.ProductionReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: YKYB
 * @Date: 2025/10/2 16:37
 * @Description:
 */
@RestController
@RequestMapping("/report")
public class ProductionReportController {
    @Autowired
    private ProductionReportService productionReportService;

    /**
     * 分页多条件查询报工单
     */
    @GetMapping("/page")
    public Result<PageInfo<ProductionReport>> page(ProductionReport report,
                                                   @RequestParam(defaultValue = "1") int pageNum,
                                                   @RequestParam(defaultValue = "10") int pageSize) {
        return productionReportService.selectProductionReport(report, pageNum, pageSize);
    }
    /**
     * 根据ID查询单条报工单
     */
    @GetMapping("/{id}")
    public Result<ProductionReport> getById(@PathVariable Long id) {
        return productionReportService.selectById(id);
    }

    /**
     * 编辑报工单
     */
    @PutMapping
    public Result update(@RequestBody ProductionReport report) {
        return productionReportService.updateProductionReport(report);
    }

    /**
     * 状态变更-确认
     */
    @PutMapping("/status/confirm/{id}")
    public Result confirm(@PathVariable Long id) {
        return productionReportService.updateStatus1(id);
    }

    /**
     * 状态变更-通过
     */
    @PutMapping("/status/pass/{id}")
    public Result pass(@PathVariable Long id) {
        return productionReportService.updateStatus2(id);
    }

    /**
     * 状态变更-不通过
     */
    @PutMapping("/status/reject/{id}")
    public Result reject(@PathVariable Long id) {
        return productionReportService.updateStatus3(id);
    }

    /**
     * 单条删除（逻辑删除）
     */
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Long id) {
        return productionReportService.deleteById(id);
    }

    /**
     * 批量删除（逻辑删除）
     */
    @DeleteMapping("/batch")
    public Result batchDelete(@RequestBody Long[] ids) {
        return productionReportService.batchDelete(ids);
    }
}
